<?php

if (!empty($_SESSION['login'])&&!empty($_SESSION['email'])){
$db  =new Mypdo();


$loyerManager = new LoyerManager($db);
$locManager = new LocationManager($db);
$locaManager = new LocataireManager($db);
$persManager = new PersonneManager($db);
$listeLoyer = $loyerManager->getListByStatut(0);
?>

<h1>Loyer Impayer</h1>
<input type="radio" name="relance" id="relance" value="1" checked /><label for="relance">Première Relance</label>
<input type="radio" name="relance" id="relance" value="2" /><label for="relance">Deuxième Relance</label>

<table class="tableau">
    <tr>
    <tr>
        <th>Location</th>
        <th>Locataire</th>
        <th>Date</th>
        <th>Détail</th>
        <th>Imprimer</th>
    </tr>
    <?php
    $ligne = 0;

    foreach ($listeLoyer as $value) {
        $ligne++;
        $loc = $locManager->getLoc($value->getIdLoc());
        $pers = $locaManager->getPersonne($value->getIdLoca());

    ?>
    <tr>
        <td><?php echo $loc->getNomLoc(); ?></td>
        <?php if(gettype($pers) == 'object'){
            ?><td><?php echo $pers->getNomPers().' '.$pers->getPrenomPers(); ?></td><?php
        }else{
            ?><td><?php
            foreach ($pers as $val) {
                echo $val->getNomPers().' '.$val->getPrenomPers()."<br/>";
            } ?>
            </td><?php
        } ?>

        <td><?php echo $value->getDateLoyer(); ?></td>
        <td><input id="detail" name="detail" type="button" onclick="document.location.href='index.php?page=214&idla=<?php echo $value->getIdLoca(); ?>&idl=<?php echo $value->getIdLoc(); ?>&date=<?php echo $value->getDateLoyer(); ?>'" /></td>
        <td>
            <form method="post" action="include/pages/impRelance.php" target="_blank">
                <input class="val_relance" type="hidden" value="1" name="choix" id="choix"/>
                <input type="hidden" value="<?php echo $loc->getIdLoc(); ?>" name="id_loc" id="id_loc"/>
                <input type="hidden" value="<?php echo $value->getDateLoyer(); ?>" name="date_loyer" id="date_loyer"/>
            <?php if(gettype($pers) == 'object'){ ?>
                <input type="hidden" value="<?php echo $pers->getIdPers(); ?>" name="id_pers" id="id_pers"/>
                <input type="submit" value="Relance" />
            <?php }else{ ?>

                <label for="id_pers" hidden="" class="changer_imp<?php echo $ligne; ?>">Personne : </label>
                <select id="id_pers" name="id_pers" required="required" hidden="" class="changer_imp<?php echo $ligne; ?>">
                    <option>Sélectionner...</option><?php
                    foreach ($pers as $value) {
                  ?><option value="<?php echo $value->getIdPers(); ?>"><?php echo $value->getNomPers().' '.$value->getPrenomPers(); ?></option><?php
                    }
              ?></select><?php
             ?> <input name="imp" id="imp-<?php echo $ligne; ?>" class="change_imp change_imp<?php echo $ligne; ?>" type="button" value="Relance"/>
                <input type="submit" class="submit<?php echo $ligne; ?>" style="display:none;"><?php
            } ?>



            </form>
        </td>
    </tr>
    <?php

    }


    ?>
</table>

<?php }
else{
header('Location: index.php');
}